import { getToken, removeToken, setToken } from "@/utils";
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
interface initialState {
    token:string
}
const initialState:initialState = {
    token: getToken() || "",
}
const userStore = createSlice({
  name: "user",
  initialState,
  reducers: {
    setTokens(state,action:PayloadAction<string>){
        setToken(action.payload)
        state.token = action.payload
    },
    logout(state){
        removeToken()
        state.token = ""
    }
  },
});

export const { setTokens,logout } = userStore.actions;
export default userStore.reducer;